
<?php

class Teacher extends Controller {

    function Teacher() {
        parent::Controller();
        $this->load->model('mod_teacher');
    }

    //=====================function for load page muster======================//

    function index() {
        if($this->check_session()){
        $this->load->view("master");
        }  else {
            redirect('admin/');
            exit();
        }
    }

    //===================function for viewing teacher===========================//
    function manager() {
        if($this->check_session()){
        $query_teacher['value_teacher'] = $this->mod_teacher->select_teacher();
        $this->load->view('master', $query_teacher);
        $data['title'] = 'teachers';
        }  else {
            redirect('admin/');
            exit();
        }
    }

    //===========================this is function for adding teacher data============================//

    function add() {
        if($this->check_session()){
        $data['title'] = 'this is the add new page';
        $this->load->helper("mgpage");
        $this->form_validation->set_rules('txtTeach_n', 'Teachername', 'required|trim|min_length[4]|max_length[30]');
        //$this->form_validation->set_rules('txtstu_n', 'Studentname', 'required|trim|max_length[20]');

        //$this->form_validation->set_rules('txtdate', 'Date', 'required|trim|max_length[30]');
        //$this->form_validation->set_rules('txtclas_time', 'class and time', 'required|trim|max_length[30]');
        //$this->form_validation->set_rules('txtarea', 'Detail', 'required|trim|max_length[30]');
        if ($this->input->post('btn_submit')) {
            if ($this->form_validation->run() == false) {
                $this->load->view('master', $data);
            } else {
                $this->mod_teacher->add();
                $this->session->set_userdata('teacher_ms', '<br/><dl id="system-message"><dd class="message message"><ul><li>Add Successful!</li></ul></dd></dl>');
                redirect('teacher/manager');
            }
        } else {
            $this->load->view('teacher/add');
        }
        }  else {
            redirect('admin/');
            exit();
        }
    }

    //==========================this is function for editing teacher management==================================//

    function edit() {
        if($this->check_session()){
        if ($this->input->post('btn_submit')) {
            $this->mod_teacher->checkedit();
            $this->session->set_userdata('edit_teacher', '<br/><dl id="system-message"><dd class="message message"><ul><li>Updated Successful!</li></ul></dd></dl>');
            redirect('teacher/manager');
        } else {
            $getdata['getresult'] = $this->mod_teacher->selectedit();
            $this->load->view('master', $getdata);
        }
        }else{
            redirect('admin/');
            exit();
            }
    }

    //========================this is function for deleting data from teacher================================//

    function delete() {
        if($this->check_session()){
        if ($this->mod_teacher->delete()) {
            $this->session->set_userdata('del_teacher', '<br/><dl id="system-message"><dd class="message message"><ul><li>Deleted Successful!</li></ul></dd></dl>');

            redirect('teacher/manager');
        }
        }  else {
            redirect('admin/');
            exit();
        }
    }
    
    
     //========this is function for using checking session=============
    
     public function check_session() {
        if ($this->session->userdata('use_username')) {
            return true;
        } else {
            return false;
        }
    }

}